import { Component, Input, OnInit, OnChanges } from '@angular/core';
import { Assembly, AssemblyStyles, AssemblyValidators, AssemblyConfigs } from '../../../fb-design.model'
import { SelectItem, DialogService } from 'primeng/primeng';
import { QkTableColAttributes } from '../common/qk-tablecol-attributes.component';

@Component({
    selector: 'qk-table-attributes',
    templateUrl: 'qk-table-attributes.component.html',
    styleUrls: ['qk-table-attributes.component.scss'],
    providers: []
})
export class QkTableAttributes implements OnInit {
    @Input() assembly: Assembly;
    @Input() 
    set names(names: string[]){
        let temp = [];
        names.forEach(e => temp.push({label: e, value: e}));
        this.nameItems = temp;
    }

    nameItems: SelectItem[];

    ngOnInit() {
    }

    constructor(public dialogService: DialogService) {
    }

    editCols() {
        const ref = this.dialogService.open(QkTableColAttributes, {
            header: '列属性编辑',
            width: '450px',
            contentStyle: { 'height': '450px' },
            data: {
                columns: this.assembly.configs.columns
            }
        });
        ref.onClose.subscribe(data => {
            this.assembly.configs.columns = JSON.stringify(data);
        });
    }
}